package counter.com.baomidou.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import counter.com.baomidou.entity.Countertrojan;
import counter.com.baomidou.service.ICountertrojanService;
import counter.com.common.FileProperties;
import counter.com.common.Result;
import counter.com.connproperty.counter.CounterAddTrojanProperty;
import counter.com.connproperty.counter.CounterDeleteTrojanProperty;
import counter.com.connproperty.counter.CounterTrojanSearchProperty;
import counter.com.myservice.FileController;
import counter.com.myservice.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.util.Arrays;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-11-08
 */
@RestController
@RequestMapping("/countertrojan")
public class CountertrojanController {

    @Autowired
    ICountertrojanService service;

    @PostMapping("/search")
    public Result search(@RequestBody CounterTrojanSearchProperty data) {
        Page<Countertrojan> page = new Page<>(data.getPage(), data.getPagesize());
        IPage<Countertrojan> iPage = service.page(page);
        return Result.success(iPage);
    }

    @PostMapping("/add")
    public Result add(@RequestBody CounterAddTrojanProperty data) {
        Countertrojan trojan = new Countertrojan();
        LambdaQueryWrapper<Countertrojan> wrapper = new LambdaQueryWrapper<>();
        trojan.setName(data.getName());
        trojan.setType(data.getType());
        trojan.setFilepath(data.getFilepath());
        trojan.setFilename(data.getFilename());
        trojan.setCreatedtime(LocalDateTime.now());
        System.out.println(data);
        if (service.save(trojan)) {
            return Result.success("成功添加");
        } else {
            return Result.fail("添加失败");
        }
    }

    @PostMapping("/delete")
    public Result delete(@RequestBody CounterDeleteTrojanProperty data) {
        if (service.removeByIds(Arrays.asList(data.getIds()))) {
            return Result.success("删除成功");
        } else {
            return Result.fail("删除失败");
        }
    }

}
